package cn.android.x.parent;

import android.os.Bundle;
import android.view.View;

import com.gyf.immersionbar.ImmersionBar;

import cn.android.x.R;
import cn.sinothk.hussars.parent.TitleBaseActivity;

public abstract class AppTitleBaseActivity extends TitleBaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutResId());
        ImmersionBar.with(this)
                .statusBarDarkFont(true).init();
    }

    protected abstract int getLayoutResId();

    @Override
    public void setViewTitle(String centerTxt) {
        titleBarView = this.findViewById(R.id.titleBarView);

        titleBarView.setLeftIcon(R.drawable.back_icon);
        titleBarView.setLeftVisible(View.VISIBLE);
        titleBarView.setLeftViewClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        titleBarView.setCenterTxt(centerTxt);
        titleBarView.setCenterTxtColor(R.color.title_txt);
    }

    public void setViewTitle(String centerTxt, String rightTxt, View.OnClickListener clickListener) {
        titleBarView = this.findViewById(R.id.titleBarView);

        titleBarView.setLeftIcon(R.drawable.back_icon);
        titleBarView.setLeftVisible(View.VISIBLE);
        titleBarView.setLeftViewClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        titleBarView.setCenterTxt(centerTxt);
        titleBarView.setCenterTxtColor(R.color.title_txt);

        titleBarView.setRight1Txt(rightTxt, clickListener);
        titleBarView.setRight1TxtColor(R.color.title_txt);
    }

    public void setViewTitle(String centerTxt, int imgResId, View.OnClickListener clickListener) {
        titleBarView = this.findViewById(R.id.titleBarView);

        titleBarView.setLeftIcon(R.drawable.back_icon);
        titleBarView.setLeftVisible(View.VISIBLE);
        titleBarView.setLeftViewClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        titleBarView.setCenterTxt(centerTxt);
        titleBarView.setCenterTxtColor(R.color.title_txt);

        titleBarView.setRight1Icon(imgResId, clickListener);
    }

    public void setViewTitleRightIcon(int imgResId) {
        titleBarView.setRight1Icon(imgResId);
    }

//    public void dealKeybord(EditText editText) {
//        if (ModelUtils.isEMUI() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
//            editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
//            editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
//        }
//    }
}
